package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

public class RegDemo {
    public static void main(String[] args) throws  Exception{
        Scanner sc=new Scanner(System.in);
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");
        //声明表
        Statement statement = connection.createStatement();
        System.out.println("请输名字");
        String username=sc.nextLine();
        System.out.println("请输入密码");
        String password1=sc.nextLine();
        System.out.println("请输入昵称");
        String nickname=sc.nextLine();
        System.out.println("请输入年龄");
        int age=sc.nextInt();
        String sql="insert into userinfo(username, password, nickname, age)" +
                "    value ('"+username+"','"+password1+"','"+nickname+"',"+age+")";

        int i = statement.executeUpdate(sql);
        if (i>0){
            System.out.println("注册成功!");
        }
        connection.close();
    }
}
